let express = require("express")();
let expressStatic = require("express-static")
let mysql = require("mysql");
const { request, response } = require("express");
let port = 85;
// 规划一个数据库连接
let sql = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "1234567",
    database: "test",
    timezone: "08:00"
});
//尝试连接
sql.connect();
//获取到前端的请求后才能查询数据
//首页
express.get("/getNewsList", (request, response) => {
        sql.query(`SELECT * FROM picture`, (error, data) => {
            response.send(data)
                // console.log(data);
        })
    })
    // 详情页
express.get("/getNews", (request, response) => {
    let id = request.query.id;
    sql.query(`SELECT * FROM picture WHERE id=${id}`, (error, data) => {
        if (error) {
            console.log(error);
            response.send("error")
        } else {
            response.send(data[0])
        }
    })

})
express.use(expressStatic(__dirname + `/lll`));
console.log(`running at ${port}`);
express.listen(port)